package com.javaGather.demo3;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Test2 {
    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter String");
        String s = scanner.nextLine();

        HashMap<Character, Integer> hashMap = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            char key = s.charAt(i);
            Integer value = hashMap.get(key);
            if (value == null) {
                value = 1;
            } else {
                value++;
            }
            hashMap.put(key, value);
        }
        Set<Map.Entry<Character, Integer>> entries = hashMap.entrySet();
        for (Map.Entry<Character, Integer> entry : entries) {
            System.out.println("字符：" + entry.getKey() + " 出现次数：" + entry.getValue());
        }


    }
}
